/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-07-12 21:29:45
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-07-13 09:45:03
 * @FilePath: /yjl/NetProjectVideo/http_server/server.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"./httplib.h"
using namespace httplib;

void HelloWorld (const Request& req,Response& rsp)
{
    rsp.body="Hello world!";
}

void Numbers(const Request& req,Response& rsp)
{
    // 存放：正则表达式匹配的规则数据
    std::string num=req.matches[1];
    rsp.set_content(num,"text/plain");// 添加数据，并设置为Content-Type类型

}

void Multipart(const Request& req,Response& rsp)
{
    if(req.has_file("file1")==false)
    {
        rsp.status=400;
        return ;
    }
    MultipartFormData file=req.get_file_value("file1");
    std::cout<<file.filename<<std::endl;
    std::cout<<file.content<<std::endl;

}
int main()
{
    Server server;

    // 1、设置一个静态资源根目录----为当前目录下的wwwroot
    server.set_mount_point("/","/wwwroot");

    // 2、添加：请求--处理 函数的映射信息
    server.Get("/hi",HelloWorld);
    
    server.Get("/numbers/(\\d+)",Numbers);
    server.Post("/multipart",Multipart);
    server.listen("0.0.0.0",9090);
    return 0;
}